@extends('admin.main')

@section('content')
<div class="wrapper wrapper-content">
	<div class="m-b">
		<a href="{{session('listUrl')}}" class="btn btn-default"><i class="fa fa-arrow-left"></i> 返回列表</a>
	</div>
	<div class="ibox float-e-margins">
		<div class="ibox-title">
			<h5>新建用户</h5>
		</div>
		<div class="ibox-content">
			<form id="frmAddUser" method="post" class="form-horizontal" role="form">
				<div class="form-group">
					<label class="col-sm-2 control-label">帐户</label>
					<div class="col-sm-4">
						<input type="text" name="username" class="form-control" required="" autofocus>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">密码</label>
					<div class="col-sm-4">
						<input type="password" name="password" class="form-control" required="">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">确认密码</label>
					<div class="col-sm-4">
						<input type="password" name="repassword" class="form-control" required="">
					</div>
				</div>
				<div class="hr-line-dashed"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">姓名</label>
					<div class="col-sm-4">
						<input type="text" name="realname" class="form-control">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">邮箱</label>
					<div class="col-sm-6">
						<input type="email" name="email" class="form-control">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">手机</label>
					<div class="col-sm-4">
						<input type="text" name="mobile" class="form-control">
					</div>
				</div>
				<div class="hr-line-dashed"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">身份证号</label>
					<div class="col-sm-4">
						<input type="text" name="cardid" class="form-control">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">性别</label>
					<div class="col-sm-10">
						<label class="radio-inline i-checks">
							<input type="radio" value="男" name="sex" checked=""> <i></i>
							男
						</label>
						<label class="radio-inline i-checks">
							<input type="radio" value="女" name="sex"> <i></i>
							女
						</label>
						<label class="checkbox-inline i-checks m-l-md">
							<input type="checkbox" name="status" value="1"> 帐户已禁用
						</label>
					</div>
				</div>
				<div class="hr-line-dashed"></div>
				<div class="form-group">
					<div class="col-sm-4 col-sm-offset-2">
						<input type="hidden" name="_token" value="{{ csrf_token() }}">
						<button class="btn btn-primary btn-w-m" type="submit">提交</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
@endsection

@section('pageheader')
<link href="{{asset('assets/css/plugins/iCheck/custom.css')}}" rel="stylesheet">
@endsection

@section('pagescript')
<script src="{{asset('assets/js/plugins/iCheck/icheck.min.js')}}"></script>
<script src="{{asset('assets/models/userModel.js')}}"></script>
<script>
	$(document).ready(function () {
		$("#sidebar li[rel='entrust']").addClass("active")
			.find("ul").addClass("in")
			.find("li[rel='2']").addClass("active");

    $('.i-checks').iCheck({
      checkboxClass: 'icheckbox_square-green',
      radioClass: 'iradio_square-green',
    });
  });

  $("#frmAddUser").on('submit', function(){
  	if(this.repassword.value != this.password.value){
  		this.repassword.focus();
  		return false;
  	}
  	var formdata = $(this).serialize();
		userModel.create(formdata, function(result){
			window.location.href = "{{ url('admin/user') }}";
		}, failure);
		return false;
  });

  var failure = function(data){
		dialog({content:'<i class="fa fa-info-circle"></i> '+data.responseJSON}).showModal();
	};
</script>
@endsection
